﻿#region File Description
//-----------------------------------------------------------------------------
// SampleCamera.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;
using RainEngine.SceneManagement;
#endregion

namespace RainEngine.SceneNodes
{
    public enum SampleArcBallCameraMode
    {
        /// <summary>
        /// A totally free-look arcball that orbits relative
        /// to its orientation
        /// </summary>
        Free = 0,

        /// <summary>
        /// A camera constrained by roll so that orbits only
        /// occur on latitude and longitude
        /// </summary>
        RollConstrained = 1

    }

    /// <summary>
    /// ArcBallCamera类
    /// </summary>
    public class ArcBallCameraSceneNode:CameraSceneNode 
    {
        
        /// <summary>
        /// Create an arcball camera that allows free orbit around a target point.
        /// </summary>
        public ArcBallCameraSceneNode(GraphicsDevice graphicsDevice, Scene setScene, Vector3 setPosition, Vector3 cameraLookAt, SampleArcBallCameraMode controlMode)
            : base(graphicsDevice, setScene, setPosition, cameraLookAt)
        {
            
        }

        public override void UpdateViewMatrix(bool updateProjection)
        {
            Matrix rotMx = Matrix.CreateFromQuaternion(pose.Rotation);
            Vector3 upVector = Vector3.Transform(Vector3.Up, rotMx);

            //cameraLookAt = Vector3.Transform(Vector3.Forward, rotMx);
            //cameraLookAt += pose.Position;
            viewMatrix = Matrix.CreateLookAt(pose.Position, target, Vector3.Up);
            if (updateProjection)
            {
                //  物理视锥体，very distant internal far plane           
                projectionMatrix = Matrix.CreatePerspectiveFieldOfView(cameraFov, AspectRatio, nearPlane, internalFarPlane);
                
            }
            hasChanged = true;
        }
    }
}